/*
 *  Copyright 2001-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ar.uba.fi.posgrado.economy.model;

import ar.uba.fi.posgrado.common.model.PosgradoEnum;


/**
 * Estado de la deuda
 * 
 * @author pablo.tortorella
 * 
 */
public enum DebtStatus implements PosgradoEnum {
	// Balanced = Con Saldo
    // Active = Vigente
    // Cuando se crea esta Inactiva por defecto
    Cancelled, Paid, Balanced, Active, Inactive, Vencida;
	
    // TODO Pasar a ingles ConMora

    /**
     * @see ar.uba.fi.posgrado.common.model.PosgradoEnum#toStringValue()
     */
    public String toStringValue() {
        if (this.equals(DebtStatus.Cancelled)) {
            return "CANCELADA";
        }
        else if (this.equals(DebtStatus.Paid)) {
            return "PAGADA";
        }
        else if (this.equals(DebtStatus.Balanced)) {
            return "CON SALDO";
        }
        else if (this.equals(DebtStatus.Active)) {
            return "VIGENTE";
        }
        else if (this.equals(DebtStatus.Inactive)) {
            return "NO VIGENTE";
        }
        else if (this.equals(DebtStatus.Vencida)) {
            return "VENCIDA";
        }
        
        return "NO VIGENTE";
    }
    
    public static DebtStatus fromStringValue(String stringValue) {
        if (stringValue.equals(DebtStatus.Cancelled.toStringValue())) {
            return Cancelled;
        }
        if (stringValue.equals(DebtStatus.Paid.toStringValue())) {
            return Paid;
        }
        if (stringValue.equals(DebtStatus.Balanced.toStringValue())) {
            return Balanced;
        }
        if (stringValue.equals(DebtStatus.Active.toStringValue())) {
            return Active;
        }
        if (stringValue.equals(DebtStatus.Inactive.toStringValue())) {
            return Inactive;
        }
        if (stringValue.equals(DebtStatus.Vencida.toStringValue())) {
            return Vencida;
        }
        
        return Inactive;
    }
	
    /**
     * Devuelve true cuando el estado es:
     * <ul>
     *  <li> {@link DebtStatus#Active} </li>
     *  <li> {@link DebtStatus#Balanced} </li>
     *  <li> {@link DebtStatus#Vencida} </li>
     * </ul>
     * @return (true|false)
     */
    public boolean appliesAccountModification() {
        if (    this.equals(DebtStatus.Active) || 
                this.equals(DebtStatus.Balanced) ||
                this.equals(DebtStatus.Vencida)) {
            return true;
        }
        return false;
    }
    
    public boolean isCollectable() {
    	return this.appliesAccountModification();
    }
    
    /**
     * @see java.lang.Enum#toString()
     */
    @Override
    public String toString() {
        return this.toStringValue();
    }

}
